package org.roger.almeida.server.services;

import java.util.ArrayList;
import java.util.List;

import javax.jdo.PersistenceManagerFactory;
import javax.jdo.Query;

import org.roger.almeida.client.model.FeatureVO;
import org.roger.almeida.client.services.FeatureService;
import org.roger.almeida.server.factories.EntityManagerRepository;
import org.roger.almeida.server.model.Feature;

public class FeatureServiceImpl implements FeatureService {

	@Override
	public List<FeatureVO> findFeaturesByProjectId(Long projectId) {
		PersistenceManagerFactory persistenceManagerFactory = EntityManagerRepository.get();
		Query query = persistenceManagerFactory.getPersistenceManager().newQuery(Feature.class, "id == projectId");
		query.declareParameters("Long projectId");
		List<Feature> resultSet = (List<Feature>) query.execute(projectId);
		List<FeatureVO> resultVOs = new ArrayList<FeatureVO>();
		for (Feature feature : resultSet) {
			FeatureVO featureVO = new FeatureVO();
			featureVO.setBusinessValue(feature.getBusinessValue());
//			TODO copiar os dados aqui
			resultVOs.add(featureVO);
		}
		
		return resultVOs;
	}

}
